package cn.itcast.bos.service.transit.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.transit.InOutStorageInfoRepository;
import cn.itcast.bos.dao.transit.SignInfoRepository;
import cn.itcast.bos.dao.transit.TransitInfoRepository;
import cn.itcast.bos.domain.transit.SignInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.index.WayBillIndexRepository;
import cn.itcast.bos.service.transit.SignInfoService;

@Service
@Transactional
public class SignInfoServiceImpl implements SignInfoService {
	@Resource
	private SignInfoRepository repository;
	@Resource
	private TransitInfoRepository transitInfoRespository;
	@Resource
	private WayBillIndexRepository indexRepsitory;
	@Override
	public void save(String transitInfoId, SignInfo model) {
		// 保存签收录入信息
		repository.save(model);
		// 查询运输配送对象
		TransitInfo transitInfo = transitInfoRespository.findOne(Integer.parseInt(transitInfoId));
		// 关联配送信息
		transitInfo.setSignInfo(model);
		//更改状态
		if (model.getSignType().equals("正常")) {
			transitInfo.setStatus("正常签收");
			transitInfo.getWayBill().setSignStatus(3);
			//更改索引库状态
			indexRepsitory.save(transitInfo.getWayBill());
		}else {
			transitInfo.setStatus("异常");
			transitInfo.getWayBill().setSignStatus(4);
			//更改索引库状态
			indexRepsitory.save(transitInfo.getWayBill());
		}
	}
}
